package com.zyn.es.basic;

import java.util.HashMap;
import java.util.Map;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.elasticsearch.action.index.IndexResponse;

/**
 * 添加数据
 * 
 * @author tongyufu
 *
 */
public class IndexAPI extends EsClient {

    Logger log = LogManager.getLogger();

    public static void main(String[] args) {
        IndexAPI index = new IndexAPI();
        index.useMap();
    }

    public void useMap() {
        super.initClient();
        log.info("================================");
        Map<String, Object> json = new HashMap<String, Object>();
        json.put("title", "New version of Elasticsearch released!");
        json.put("content", "Version 5.0 released today!");
        json.put("priority", 10);
        json.put("tags", new String[] { "announce", "elasticsearch", "release" });

        IndexResponse response = client.prepareIndex(INDEX, TYPE, "1").setSource(json).get();
        super.printResponse(response);
        client.close();
        log.info("================================");
    }

}
